/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package info.autoproduktion;

public class Lieferant extends Thread {

    private int Lieferfrist, Auftragsvolumen;
    private int produkt;
    private Lager lager;

    public Lieferant(int produkt, int Frist, int Volumen, Lager lager) {
        super(lager.gibTeil(produkt));
        this.produkt = produkt;
        Lieferfrist = Frist;
        Auftragsvolumen = Volumen;
        this.lager = lager;
    }

    public void run() {
        for (int i = 1; i <= Auftragsvolumen; i++) {
            try {
                int diff = (int) (Math.random() * Lieferfrist);
                sleep(diff);
            } catch (InterruptedException e) {
            }
            lager.liefern(produkt);
        }
    }
}
